package demo2;

import java.util.Arrays;

import static java.util.Arrays.compare;
import static java.util.Arrays.sort;

class Student implements Comparable {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int compareTo(Object o) {
        Student student = (Student)o;
        return this.age - student.age;
    }

    @Override
    public String toString() {
        return "name " + this.name + "age " + this.age;
    }
}
public class Test {
    public static void main(String[] args) {
        Student student1 = new Student("zhangSan",18);
        Student student2 = new Student("lisi",30);
        Student student3 = new Student("wangWu",29);

        Student[] student = {student1,student2,student3};

        /**
         * sort(待排序数组,Comparator<? super T> cmp(比较器))
         * 通过不同选择比较器,来实现不同排序
         */
        sort(student);

        System.out.println(Arrays.toString(student));
    }
}
